/*** BEGIN META {
 "name" : "Build Jobs Matching Pattern",
 "comment" : "Find all jobs with names matching the given pattern and builds them.",
 "parameters" : [ "jobPattern" ],
 "core": "1.409",
 "authors" : [
 { name : "Kristian Kraljic" }
 ]
 } END META**/
// 基于正则表达式匹配job的完整名称来批量启动job
import jenkins.model.*
import hudson.model.*

// Pattern to search for. Regular expression.
def jobPattern = ".*efp-5.*"

def matchedJobs = Jenkins.instance.getAllItems(Job.class).findAll { job ->
    job.fullName =~ /$jobPattern/
}

matchedJobs.each { job ->
    println "Scheduling matching job ${job.fullName}"
    job.scheduleBuild(new Cause.UserIdCause())
}
return
